{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Solving a quadratic equation\n", "\n", "If we have an equation in the form **a**x2 + **b**x + **c** = 0, to solve **x** the following formula is applied:\n", "\n", "\n", "In Python, recall that multiplication is done with an asterisk \\* while power is indicated by two \\*\\*. For example, 2\\*3 is 6 y 2\\*\\*3 is 8.\n", "\n", "The square root can be calculated using ```1/2``` as the right operand of the power operator, for instance ```4**(1/2)``` will equal 2.\n", "\n", "To ask a user to enter data, the `input()` function is used. This function admits as a parameter a text that will be shown to the user as an aid to request the input data. For example,\n", "`text = input(\"Enter a text: \")`\n", "\n", "If we want the entered text to be treated as an integer in order to perform mathematical operations, we must convert it using the `int()` function. This is also called **casting**. For example,\n", "`number = int(input(\"Enter an integer number: \")`\n", "\n", "If we want the entered number to have decimals, the conversion must be done using the `float()` function. For example,\n", "`floating_number = float(input(\"Enter a float number: \")`\n", "\n", "\n", "So far, with all the previous explanation, **develop the following program**:\n", "\n", "A program to calculate the solution to a quadratic equation like ax2 + bx + c = 0. It will ask the user for the values of a, b and c, calculate x (possibly have 2 solutions) and print the result on the screen.\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.4" } }, "nbformat": 4, "nbformat_minor": 4 }